<?php

class FaqDao extends Dao {

    public function injectDependencies() {

    }

    public function findAll() {
        $this->initConnection();
        $StSql = TQuery::getSqlFindAllQuestions();
        $tQuery = $this->tMysqli->exec($StSql);
        $ArPerguntas = array();
        while($ArPerguntaData = mysqli_fetch_assoc($tQuery)) {
            $ArPerguntas[] = new Pergunta($ArPerguntaData);
        }
        $this->closeConnection();
        return $ArPerguntas;
    }

    public function findById($IDFaq) {
        $this->initConnection();
        $this->tMysqli->escape($IDFaq);
        $StSql = TQuery::getSqlFindQuestionById($IDFaq);
        $tQuery = $this->tMysqli->exec($StSql);
        while($ArPerguntaData = mysqli_fetch_assoc($tQuery)) {
            $Pergunta = new Pergunta($ArPerguntaData);
        }
        $this->closeConnection();
        return isset($Pergunta) ? $Pergunta : false;
    }

    public function save($IDUsuario, $ArDados) {
        $this->initConnection();
        $this->tMysqli->escape($ArDados);
        $StSql = TQuery::getSqlInsertQuestion($IDUsuario, $ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function update($IDUsuario, $ArDados) {
        $this->initConnection();
        $this->tMysqli->escape($ArDados);
        $StSql = TQuery::getSqlUpdateQuestion($IDUsuario, $ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function delete($IDFaq) {
        $this->initConnection();
        $this->tMysqli->escape($IDFaq);
        $StSql = TQuery::getSqlDeleteQuestion($IDFaq);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

}

?>
